package com.cea.papyrustest.uml.createcommand;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.commands.UMLElementCreateCommand;

/**
 * Test class for {@link Class} factory
 * @author Patrick Tessier
 */
public class ConnectorCreateCommandTest extends PapyrusCommandTest{


	protected Class class_0;
	/**
	 * Default constructor
	 * @param name the name oif the test case
	 */
	public ConnectorCreateCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Class.class,model);
		stack.execute(papyrusCommand);
		//Class_0 is created!
		class_0=(Class)model.getPackagedElement("Class_0");
		papyrusCommand= new UMLElementCreateCommand(org.eclipse.uml2.uml.Connector.class,class_0);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		Element clazz=class_0.getOwnedConnector("Connector_0");
		assertNotNull("the connector is not created",clazz);
		assertTrue("this is not a connector",((clazz)instanceof Connector));
		
		// undo
		stack.undo();
		assertNull("the class exist!",class_0.getOwnedConnector("Connector_0"));
		
		// redo
		stack.redo();
		clazz=class_0.getOwnedConnector("Connector_0");
		assertNotNull("the connector is created",clazz);
		assertTrue("this is not a connector",((clazz)instanceof Connector));
	}
}
